home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000109_icon-group-sender_Wed Oct 25 08:09:54 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9PF9kc09413
for icon-group-addresses; Wed, 25 Oct 2000 08:09:46 -0700 (MST)
Message-Id: <200010251509.e9PF9kc09413@baskerville.CS.Arizona.EDU>
Date: Tue, 24 Oct 2000 21:23:19 -0400
From: David Gamey <dgamey@sympatico.ca>
X-Accept-Language: en
To: icon-group@cs.arizona.edu
CC: Chris.D.Tenaglia@jci.com
Subject: Re: Icon beginner
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1745
Chris.D.Tenaglia@jci.com wrote:
>
> I like simple things like...
>
> procedure despace(str)
> new := ""
> every byte := !string do if byte ~== " " then new ||:= byte
Ooops, this typo "!string" instead of "!str" won't work. I'd expect to
see a type error here since string is a builtin function.
> return new
> end
>
There's always 'strip' in the Icon programming library, see
http://www.cs.arizona.edu/icon/library/src/procs/strip.icn
But if you insist on doing it yourself try a slightly terser version of
Chris's code:
procedure despace(str)
new := ""
every new ||:= ( " " ~== !str )
return new
end
In the above, every generates each character in str. Then if the ~==
succeeds, the ~== operator returns its' right argument for the
concatenation.
Chris's example is probably easier for someone new to Icon to decipher.
After writing Icon for a while I find the second is clearer and more
straightforward.
You could with minor changes make this work like strip. However, it
wouldn't likely be as elegant or as fast. An interesting difference in
the use of every .vs. while (and the integration of control structures
with string scanning).
> Chris Tenaglia, tech analyst, jci
>
> kaurp@cs.ucdavis.edu on 10/23/2000 01:56:42 PM
>
> To: icon-group@CS.Arizona.EDU
> cc:
> bcc:
>
> Subject: Icon beginner
>
> Hi,
> I'm just learning icon and I'm stumped with a particular problem. I'm
> suppose to delete all occurrences of a space from a sentence, i.e. "Hi
> there" should become "Hithere". Any ideas of how I should approach this
> problem. I tried using the built-in delete proc. but it wasn't working.
delete works with structures (e.g. sets)
> I'd appreciate any help, thanks!
> -Cos
David Gamey